#!/bin/bash
# Author : Syuan-Rong Chen
# E-mail : calvin.atx@gmail.com
# Blog：   http://calvinit.blogspot.com
# Date : 20100812
#
# <description>
# Copyright (C) <year>  <name> <email>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see .
#
me=main.sh
. /usr/cbin/c/lang.sh
. /usr/cbin/d-cmis/$lang $me

tmp=$(ifconfig > /tmp/ip1)
tmp=$(cat /tmp/ip1 |grep "Link encap:E" > /tmp/ip2)
ipn=$(wc -l /tmp/ip2 |fmt -u|cut -d' ' -f1)
tmp=$(cat /etc/resolv.conf|grep nameserver > /tmp/dsn)
tmp=$(cat /tmp/dsn |sed s/nameserver/DNS/ > /tmp/dsn2)

clear

function itface {
	clear
	echo -e '\E[1;32m'$iftext1 ; tput sgr0
	myvar=1
	while [ $myvar -ne $ipn ]
	do
		ceth=$(cat /tmp/ip1 | grep "Link encap:E" | sed -n $myvar,1p|cut -d' ' -f1)
		cmac=$(cat /tmp/ip1 | grep "Link encap:E" | sed -n $myvar,1p |fmt -u|cut -d' ' -f5)
		cip=$(ifconfig |grep -A1 $ceth|grep "inet addr"|cut -d':' -f2|cut -d' ' -f1|sed -n 1,1p)
		csm=$(ifconfig |grep -A1 $ceth|grep "inet addr"|cut -d':' -f4|sed -n 1,1p)

		[ -z $cip ] && echo "" > /tmp/temp || printf "$ceth \t MAC:$cmac \t IP:$cip \t Mask:$csm \n"
		myvar=$(( $myvar + 1 ))
	done

	echo ""
	cat /tmp/dsn2
	echo ""
	echo -e '\E[1;32m'$iftext2 ; tput sgr0
	route -n
}

function outputMenu {

echo -e '\E[1;33m'$opmtitle; tput sgr0
echo ""
echo -e '\E[1;32m'$opmsub; tput sgr0
echo ""
echo "[w] "$opm_textw
echo "[1] "$opm_text1
echo "[2] "$opm_text2
echo "[3] "$opm_text3
echo "[4] "$opm_text4
echo ""
echo -e '\E[1;31m'"[5] "$opm_text5; tput sgr0
echo ""
echo "[c] "$opm_textc
echo "[0] "$opm_text0

echo ""
echo -ne $select0
read USERCHOICE
clear

case $USERCHOICE in
	"w") itface ;;
        "1") sudo nano /etc/network/interfaces ;;
        "2") sudo nano /etc/resolv.conf ;;
	"3") 
		macs=/etc/udev/rules.d/70-persistent-net.rules
		read -p $selectdel del
		if [ $del == "y" ]; then 
			[ ! -e $macs ] && echo $nofile || sudo rm $macs | echo $ddel
		else
			echo $nodel
		fi
		;;
	"4") sudo /etc/init.d/networking restart ;;
	"5") . /usr/cbin/d-cmis/ns.sh ;;
	"c") . /usr/cbin/c/0-ME ;;
	"0") exit 0;;
        *) echo $select1;;
esac
}

. /usr/cbin/c/domenu.sh
